﻿using Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dqs_DAL
{
	public class Test_DAL
	{
		public async void InitializeData()
		{
			using (MyDbContext db = new MyDbContext())
			{
				// 初始化数据库数据
				var student = new StudentInfo() { UserName = "student", Password = "student", FullName = "student", Phone = "13245678900", Role = 3, StuNum = "202202010506" ,AttendCount = 10};
				var student1 = new StudentInfo() { UserName = "zhangsan", Password = "zhangsan", FullName = "张三", Phone = "13245678900", Role = 3, StuNum = "202202010507" ,AttendCount = 5 };
				var teacher = new TeacherInfo() { UserName = "teacher", Password = "teacher", FullName = "teacher", Phone = "15963247898", Role = 2, TeaNum = "201203300607" };
				var teacher1 = new TeacherInfo() { UserName = "lisi", Password = "lisi", FullName = "李四", Phone = "15963247898", Role = 2, TeaNum = "2022023020205" };
				var admin1 = new AdminInfo() { UserName = "wangwu", Password = "wangwu", FullName = "王五", Phone = "15789632044", Role = 1 };
				var course = new CourseInfo() { CourseName = "数据结构", Teachers = teacher1, StartTime = DateTime.Now , EndTime = DateTime.Now.AddMonths(3)};
				var course1 = new CourseInfo() { CourseName = "c#语言基础", Teachers = teacher, StartTime = DateTime.Now, EndTime = DateTime.Now.AddMonths(3)};
				var classInfo = new ClassInfo() { ClassName = "东1-101", Course = course, IsMultimedia = true, IsOccupied = false, MaxCount = 30 };
				var classInfo1 = new ClassInfo() { ClassName = "东2-101", Course = course1, IsMultimedia = false, IsOccupied = true, MaxCount = 30 };

				course.StudentList!.Add(student);
				course1.StudentList!.Add(student1);
				course.StudentList!.Add(student);
				course1.StudentList!.Add(student1);
				db.Students.Add(student);
				db.Teachers.Add(teacher);
				db.Students.Add(student1);
				db.Teachers.Add(teacher1);
				db.Admins.Add(admin1);
				db.CourseInfos.Add(course);
				db.CourseInfos.Add(course1);
				db.ClassInfos.Add(classInfo);
				db.ClassInfos.Add(classInfo1);

				
				await db.SaveChangesAsync();
			}
		}
		
	}
}
